﻿using least_squares.models;
namespace least_squares
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var model = new RegressionModel();
            //读取数据
            model.X = MyFunctions.ListReadTxt(@$"{System.Environment.CurrentDirectory}\Year.txt");
            model.Y = MyFunctions.ListReadTxt($@"{System.Environment.CurrentDirectory}\GDP.txt");
            //计算参数
            model.Compute();
            //预测
            var gdp = model.Forecast(2021);
            Console.WriteLine($"预测2021年的GDP为{gdp.ToString("##.##")}万亿美元");
            //计算误差
            double error, gdp2021 = 17.73;
            Console.WriteLine($"实际2021年GDP为{gdp2021}万亿美元");
            error = System.Math.Abs(gdp - gdp2021) / gdp2021;
            Console.WriteLine($"预测误差为{error * 100}%");
            Console.ReadLine();
        }
    }
}